package org.skill.panel;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.math.BigDecimal;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import org.come.Jpanel.TestPetJpanel;
import org.come.bean.LoginResult;
import org.come.bean.PrivateData;
import org.come.until.AnalysisString;
import org.come.until.CutButtonImage;
import org.skill.btn.SkillTYCBtn5;

import com.tool.role.RoleData;
import com.tool.role.SkillUtil;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import org.come.Frame.MsgJframe;
import org.come.until.UserMessUntil;
import org.come.bean.Skill;
import org.come.until.FormsManagement;

 

/**
 * 技能法门面板
 *
 * @author Administrator
 */
public class SkillSMGatePanel2 extends JPanel {
    static int gd;
    //	private SkillSMPanel[] skillSMPanels;
    private static JLabel[] skillValue,
            skillBar,//熟练度
            skillArt,//技能条
            skillfmName;//技能名称
    private static ImageIcon icon;

    //	 private JLabel skillTitle; // 技能标题
    private SkillTYCBtn5 switchBtn,
            switchBtn1,
            switchBtn2;

    public SkillSMGatePanel2() {
        skillValue = new JLabel[6];
        skillArt = new JLabel[6];
        skillBar = new JLabel[6];
        skillfmName = new JLabel[6];
        //新建
        for (int i = 0; i < 6; i++) {
            skillBar[i] = new JLabel();
            skillValue[i] = new JLabel();
            skillArt[i] = new JLabel();
            skillfmName[i] = new JLabel();
        }
        //字体颜色
        for (int i = 0; i < skillValue.length; i++) {
            skillValue[i].setForeground(Color.white);
            skillfmName[i].setForeground(Color.green);
        }
        //大小样式
        for (int i = 0; i < skillValue.length; i++) {
            skillValue[i].setFont(new Font("黑体", 0, 13));
            skillfmName[i].setFont(new Font("黑体", 0, 15));
        }
        // 设置图片
        for (int i = 0; i < 6; i++) {
            skillBar[i].setIcon(CutButtonImage.getImage("inkImg/old/background/55.png", 148, 15));
            skillArt[i].setIcon(CutButtonImage.getImage("skin/8100226/button/27.png", 141, 10));

        }
        // 透明度
        for (int i = 0; i < 5; i++) {
            skillBar[i].setOpaque(false);
            skillArt[i].setOpaque(false);
            skillValue[i].setOpaque(false);
            skillfmName[i].setOpaque(false);

        }
        //位置
        for (int i = 0; i < 6; i++) {
            skillBar[i].setBounds(11 + (i * 176) > 500 ? 11 + (i * 176) - 528 : 11 + (i * 176), i > 2 ? 273 : 189, 148, 15);
            skillArt[i].setBounds(15 + (i * 176) > 500 ? 15 + (i * 176) - 528 : 15 + (i * 176), i > 2 ? 275 : 191, 141, 10);
            skillValue[i].setBounds(13 + (i * 176) > 500 ? 13 + (i * 176) - 528 : 13 + (i * 176), i > 2 ? 273 : 189, 143, 12);
            skillfmName[i].setBounds(85 + (i * 178) > 500 ? 85 + (i * 176) - 526 : 85 + (i * 178), i > 2 ? 223 : 140, 60, 38);//TODO 法门技能字体位置
        }
        //内容位置（居中）
        for (int i = 0; i < skillValue.length; i++) {
            skillValue[i].setHorizontalAlignment(SwingConstants.CENTER);
        }
        // 添加组件

        for (int i = 0; i < 6; i++) {

            this.add(skillValue[i]);
            this.add(skillArt[i]);
            this.add(skillBar[i]);
            this.add(skillfmName[i]);
        }
        LoginResult loginResult = RoleData.getRoleData().getLoginResult();

        gd = loginResult.getFmsld() / 60;
        //技能条 6条
        for (int i = 0; i < 6; i++) {

            skillArt[i].setSize(gd, skillArt[i].getHeight());
            skillValue[i].setText(loginResult.getFmsld() + "/10000");
            skillArt[i]
                    .setIcon(CutButtonImage.getImage("inkImg/hongmu/soaringSkill/技能条w140,h8px.png", 140, 10));
        }
        if ("水墨UI".equals(MyIsif.getStyle())) {
            this.setBounds(47, 65, 600, 340);//TODO  法门内置图片大小位置
        } else {
            this.setBounds(25, 80, 600, 340);//TODO  法门内置图片大小位置
        }
        this.setOpaque(false);
        this.setLayout(null);
        //按钮
        if ("水墨UI".equals(MyIsif.getStyle())) {
            switchBtn = new SkillTYCBtn5("skin/8100226/newbutton/B20.png", 1, UIUtils.COLOR_WHITE2, "切换", UIUtils.TEXT_HY19, 0, this);
            switchBtn.setBounds(50, 300, 59, 24);
            this.add(switchBtn);

            switchBtn1 = new SkillTYCBtn5("skin/8100226/newbutton/B20.png", 1, UIUtils.COLOR_WHITE2, "切换", UIUtils.TEXT_HY19, 1, this);
            switchBtn1.setBounds(230, 300, 59, 24);
            this.add(switchBtn1);

            switchBtn2 = new SkillTYCBtn5("skin/8100226/newbutton/B20.png", 1, UIUtils.COLOR_WHITE2, "切换", UIUtils.TEXT_HY19, 2, this);
            switchBtn2.setBounds(405, 300, 59, 24);
            this.add(switchBtn2);
        } else {
            switchBtn = new SkillTYCBtn5("inkImg/hongmu/1/6026.png", 1, UIUtils.COLOR_BTNPUTONG2, "切换", UIUtils.TEXT_HY19, 0, this);
            switchBtn.setBounds(55, 300, 80, 27);
            this.add(switchBtn);

            switchBtn1 = new SkillTYCBtn5("inkImg/hongmu/1/6026.png", 1, UIUtils.COLOR_BTNPUTONG2, "切换", UIUtils.TEXT_HY19, 1, this);
            switchBtn1.setBounds(235, 300, 80, 27);
            this.add(switchBtn1);

            switchBtn2 = new SkillTYCBtn5("inkImg/hongmu/1/6026.png", 1, UIUtils.COLOR_BTNPUTONG2, "切换", UIUtils.TEXT_HY19, 2, this);
            switchBtn2.setBounds(415, 300, 80, 27);
            this.add(switchBtn2);
        }
        class MListener extends MouseAdapter {
            private int numType;

            public MListener(int numType) {
                this.numType = numType;
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                if (skillfmName[numType].isVisible()) {
                    Skill skill = UserMessUntil.getskill1(skillfmName[numType].getText());
                    if (skill == null) {
                        return;
                    }
                    MsgJframe
                            .getJframe()
                            .getJapnel()
                            .SM1(skill);
                }
            }

            @Override
            public void mouseExited(MouseEvent e) {
                FormsManagement.HideForm(46);
            }
        }
        for (int i = 0; i < skillfmName.length; i++) {
            MListener l = new MListener(i);
            skillfmName[i].addMouseListener(l);
        }

    }


    /**
     * 判断种族和性别
     */
    public void getRaceSkillPanel(BigDecimal raceId, String sex) {

        // 10001 人 10002 魔 10003 仙 10004 鬼
        if (raceId.compareTo(new BigDecimal("10001")) == 0) {
            this.setIcon(CutButtonImage.getImage("inkImg/old/1/fmr.png", 524, 340));//524, 340
            if (sexisMan(sex)) {
                String skillName = "冰|睡|混";
                changeSkillBar(skillName);
                skillfmName[0].setText("清心静气");
                skillfmName[1].setText("利刃加身");
                skillfmName[2].setText("神不守舍");
                skillfmName[3].setText("以静制动");
                skillfmName[4].setText("积羽沉舟");
                skillfmName[5].setText("扑朔迷离");
            } else {
                String skillName = "冰|睡|毒";
                changeSkillBar(skillName);
                this.setIcon(CutButtonImage.getImage("inkImg/old/1/fmr2.png", 524, 340));
                skillfmName[0].setText("清心静气");
                skillfmName[1].setText("神不守舍");
                skillfmName[2].setText("神力加身");
                skillfmName[3].setText("以静制动");
                skillfmName[4].setText("扑朔迷离");
                skillfmName[5].setText("云飞烟灭");
            }
        } else if (raceId.compareTo(new BigDecimal("10002")) == 0) {
            if (sexisMan(sex)) {
                this.setIcon(CutButtonImage.getImage("inkImg/old/1/fmm.png", 524, 340));
                String skillName = "慑|牛|速";
                changeSkillBar(skillName);
                skillfmName[0].setText("幻影迷踪");
                skillfmName[1].setText("力挽狂澜");
                skillfmName[2].setText("兽魂俯首");
                skillfmName[3].setText("心无旁骛");
                skillfmName[4].setText("披荆斩棘");
                skillfmName[5].setText("困兽之斗");
            } else {
                this.setIcon(CutButtonImage.getImage("inkImg/old/1/fmm3.png", 524, 340));
                String skillName = "慑|牛|盘";
                changeSkillBar(skillName);
                skillfmName[0].setText("刚柔兼备");
                skillfmName[1].setText("势如破竹");
                skillfmName[2].setText("兽魂俯首");
                skillfmName[3].setText("妙法莲华");
                skillfmName[4].setText("暴虎冯河");
                skillfmName[5].setText("困兽之斗");
            }
        } else if (raceId.compareTo(new BigDecimal("10003")) == 0) {
            if (sexisMan(sex)) {
                this.setIcon(CutButtonImage.getImage("inkImg/old/1/fmx.png", 524, 340));
                String skillName = "雷|水|风";
                changeSkillBar(skillName);
                skillfmName[0].setText("凝神一击");
                skillfmName[1].setText("无坚不摧");
                skillfmName[2].setText("气吞山河");
                skillfmName[3].setText("一气呵成");
                skillfmName[4].setText("韬光养晦");
                skillfmName[5].setText("催筋断骨");
            } else {
                this.setIcon(CutButtonImage.getImage("inkImg/old/1/fmx.png", 524, 340));
                String skillName = "雷|水|火";
                changeSkillBar(skillName);
                skillfmName[0].setText("凝神一击");
                skillfmName[1].setText("无坚不摧");
                skillfmName[2].setText("气吞山河");
                skillfmName[3].setText("一气呵成");
                skillfmName[4].setText("韬光养晦");
                skillfmName[5].setText("催筋断骨");
            }
        } else if (raceId.compareTo(new BigDecimal("10004")) == 0) {
            if (sexisMan(sex)) {
                this.setIcon(CutButtonImage.getImage("inkImg/old/1/fmg.png", 524, 340));
                String skillName = "忘|冥|蛊";
                changeSkillBar(skillName);
                skillfmName[0].setText("法魂护体");
                skillfmName[1].setText("无坚不摧");
                skillfmName[2].setText("气聚神凝");
                skillfmName[3].setText("血蛊佑身");
                skillfmName[4].setText("韬光养晦");
                skillfmName[5].setText("明镜止水");
            } else {
                this.setIcon(CutButtonImage.getImage("inkImg/old/1/fmm2.png", 524, 340));
                String skillName = "忘|冥|魅";
                changeSkillBar(skillName);
                skillfmName[0].setText("失魂落魄");
                skillfmName[1].setText("无坚不摧");
                skillfmName[2].setText("刚柔兼备");
                skillfmName[3].setText("人鬼殊途");
                skillfmName[4].setText("韬光养晦");
                skillfmName[5].setText("妙法莲华");
            }
        } else if (raceId.compareTo(new BigDecimal("10005")) == 0) {
            if (sexisMan(sex)) {
                this.setIcon(CutButtonImage.getImage("inkImg/old/1/fml.png", 524, 340));
                String skillName = "霹|霖|摇";
                changeSkillBar(skillName);
                skillfmName[0].setText("鱼龙潜跃");
                skillfmName[1].setText("神龙摆尾");
                skillfmName[2].setText("行气如虹");
                skillfmName[3].setText("虎踞龙蟠");
                skillfmName[4].setText("积健为雄");
                skillfmName[5].setText("浩气凌云");
            } else {
                this.setIcon(CutButtonImage.getImage("inkImg/old/1/fml.png", 524, 340));
                String skillName = "霹|霖|沧";
                changeSkillBar(skillName);
                skillfmName[0].setText("鱼龙潜跃");
                skillfmName[1].setText("神龙摆尾");
                skillfmName[2].setText("行气如虹");
                skillfmName[3].setText("虎踞龙蟠");
                skillfmName[4].setText("积健为雄");
                skillfmName[5].setText("浩气凌云");
            }
        }
    }

    public void changeBtn(int typeBtn) throws Exception {
        switchBtn.setIcons(CutButtonImage.cuts("skin/8100226/button/32.png"));
        switchBtn1.setIcons(CutButtonImage.cuts("skin/8100226/button/32.png"));
        switchBtn2.setIcons(CutButtonImage.cuts("skin/8100226/button/32.png"));
    }

    /**
     * 判断男女
     */
    public static boolean sexisMan(String sex) {
        if ("男".equals(sex)) {
            return true;
        }
        return false;
    }

    /**
     * 刷新面板
     */
    public void shuamind() {
        LoginResult loginResult = RoleData.getRoleData().getLoginResult();
        gd = loginResult.getFmsld() / 100;
        //技能条 6条
        for (int i = 0; i < 6; i++) {

            skillArt[i].setSize(gd, skillArt[i].getHeight());
            skillValue[i].setText(loginResult.getFmsld() + "/100000");
            skillArt[i]
                    .setIcon(CutButtonImage.getImage("inkImg/hongmu/soaringSkill/技能条w140,h8px.png", 100, 8));
        }
        this.validate();
    }


    public void changeSkillBar(String skillName) {
        String[] skillNames = skillName.split("\\|");
        //PrivateData data = RoleData.getRoleData().getPrivateData();
        //String[] skills = data.getSkill("S");
        // 得出当前人物几转
        //int lvltrue = AnalysisString.lvltrue(RoleData.getRoleData().getLoginResult().getGrade());
        for (int i = 0; i < skillNames.length; i++) {
//			skillSMPanels[i].getSkillTitle().setText(skillNames[i]);
//			skillSMPanels[i].getSkillsName(SkillUtil.getSkillsAll(skillNames[i]), lvltrue, skills);
        }
    }


    public static JLabel[] getSkillValue() {
        return skillValue;
    }

    public static void setSkillValue(JLabel[] skillValue) {
        SkillSMGatePanel2.skillValue = skillValue;
    }

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if (icon == null) {
            icon = CutButtonImage.getImage("inkImg/old/1/fmg.png", -1, -1);
        }
        g.drawImage(icon.getImage(), 0, 0, 525, 340, this);//
    }

    public ImageIcon getIcon() {
        return icon;
    }

    public void setIcon(ImageIcon icon) {
        SkillSMGatePanel2.icon = icon;
    }

}
